package top.coolrainly.module.pb.api.user;

import org.springframework.stereotype.Service;
import top.coolrainly.framework.common.util.object.BeanUtils;
import top.coolrainly.framework.security.core.util.SecurityFrameworkUtils;
import top.coolrainly.module.pb.api.user.dto.MemberUserRespDTO;
import top.coolrainly.module.pb.service.user.MemberUserService;

import javax.annotation.Resource;

/**
 * Member 用户 API 实现类
 *
 * @author CoolRainLy
 */
@Service
public class MemberUserApiImpl implements MemberUserApi{

    @Resource
    private MemberUserService memberUserService;

    @Override
    public MemberUserRespDTO getUserByUsername(String username) {
        return BeanUtils.toBean(memberUserService.getUserByUsername(username), MemberUserRespDTO.class);
    }

    @Override
    public MemberUserRespDTO getUserByUsername(Long id) {
        return BeanUtils.toBean(memberUserService.getMemberUser(id), MemberUserRespDTO.class);
    }

    @Override
    public MemberUserRespDTO getLoginUser() {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        return BeanUtils.toBean(memberUserService.getMemberUser(userId), MemberUserRespDTO.class);
    }
}
